<template>
  <Teleport to="body">
    <div v-if="modalShow">
      <div class="model-bck" @click="close">
      </div>
      <div class="login-model">
        <div class="close">
          <img src="@/assets/img/close.png" alt="关闭" id="openis" @click="close">
        </div>
        <ul class="loginOptions">
          <li v-for="item in loginList" :key="item.id" :class="{ active: currentComop === item.id }"
            @click="setLoginType(item)">
            {{ item.name }}
          </li>
        </ul>
        <div class="login-content">
          <component :is="loginTypeDefault"></component>
        </div>
      </div>
    </div>

  </Teleport>
</template>
<script lang='ts' setup>
import codePW from '@/components/LoginModel/login/CodePW.vue'
import codeWX from '@/components/LoginModel/login/CodeWX.vue'
import codeSMS from '@/components/LoginModel/login/CodeSMS.vue'
import { ref } from 'vue'
const props = defineProps({
  modalShow: {
    type: Boolean,
    default: false
  }
})

const emit = defineEmits()
const close = (e:Event)=>{
  console.log(e);
  
  // if (e.target.id != 'openis' || e.target.id !='openBck') return

    emit('update')



  // 使用dataset属性（如果浏览器支持）  
  // if (e.target instanceof HTMLElement && e.target.dataset.isOpen !== 'bckBox') {

  //   return; // 如果data-isOpen不是'bckBox'，则不执行后续操作  

  // }  
}

const loginList = ref([
  {id:1, name: '扫码登录', component: codeWX },
  {id:2, name: '短信登录', component: codeSMS },
  {id:3,name:'密码登录',component:codePW},
])
// 默认选中的
const currentComop = ref(1)
const loginTypeDefault = ref(codeWX)
const setLoginType = (item:any) => {
  currentComop.value = item.id
  loginTypeDefault.value = item.component
}
</script>
<style scoped lang='scss'>

.model-bck{
    position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background-color: rgba(0, 0, 0, .6);
      z-index: 999;
}

.login-model{
  z-index: 1000;
  width: 457px;
  min-height: 400px;
  border-radius: 40px 40px 40px 40px;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%,-50%);
  background-color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 25px 39px 30px 40px;
  box-sizing: border-box;
}
.close{
  width: 100%;
  img{
    width: 17px;
    height: 17px;
    cursor: pointer;
    float: right;
  }
}
.login-content{
  height: 300px;
  overflow: hidden;
}

.loginOptions {
  width: 378px;
  height: 49px;
  display: flex;
  justify-content: space-evenly;
  align-items: center;
  margin-top: 25px;
  li{
    flex: 1;
    cursor: pointer;
    text-align: center;
    line-height: 49px;
    border-radius:9px;
  }
}

.active{
background-color: #c90000;
color: #fff;
}

</style>
